home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / ANTIVIR / GBCHECK.ASM next >
Encoding:
Assembly Source File  |  1995-06-16  |  11.0 KB  |  309 lines

  1. ;GB-Behavior Checker
  2. ;(C) 1995 American Eagle Publications, Inc. All Rights Reserved.
  3.  
  4. .model tiny
  5. .code
  6.  
  7.         ORG     100H
  8.  
  9. START:  jmp     GO_RESIDENT             ;jump to startup code
  10.  
  11. ;***************************************************************************
  12. ;Resident part starts here
  13.  
  14. ;Data area
  15. FIRST           DB      0             ;Flag to indicate first Int 21H, Fctn 31H
  16. VIDSEG          DW      ?             ;Video segment to use
  17. CURSOR          DW      ?             ;Cursor position
  18. VIDEO_BUF       DW      80*4 dup (?)  ;Buffer for video memory
  19.  
  20. ;***************************************************************************
  21. ;Interrupt 13H Handler
  22. OLD_13H         DD      ?               ;Original INT 13H vector
  23.  
  24. ;The Interrupt 13H hook flags attemtps to write to the boot sector or master
  25. ;boot sector.
  26. INT_13H:
  27.         cmp     ah,3                    ;flag writes
  28.         jne     DO_OLD
  29.         cmp     cx,1                    ;to cylinder 0, sector 1
  30.         jne     DO_OLD
  31.         cmp     dh,0                    ;head 0
  32.         jne     DO_OLD
  33.         call    BS_WRITE_FLAG           ;writing to boot sector, flag it
  34.         jz      DO_OLD                  ;ok'ed by user, go do it
  35.         stc                             ;else return with c set
  36.         retf    2                       ;and don't allow a write
  37. DO_OLD: jmp     cs:[OLD_13H]            ;go execute old Int 13H handler
  38.  
  39. ;This routine flags the user to tell him that an attempt is being made to
  40. ;write to the boot sector, and it asks him what he wants to do. If he wants
  41. ;the write to be stopped, it returns with Z set.
  42. BS_WRITE_FLAG:
  43.         push    ds
  44.         push    si
  45.         push    ax
  46.         call    SAVE_VIDEO              ;save a block of video for our use
  47.         push    cs
  48.         pop     ds
  49.         mov     si,OFFSET BS_FLAG
  50.         call    ASK
  51.         pushf
  52.         call    RESTORE_VIDEO           ;restore saved video
  53.         popf
  54.         pop     ax
  55.         pop     si
  56.         pop     ds
  57.         ret
  58.  
  59. BS_FLAG         DB      'An attempt is being made to write to the boot sector. Allow it? ',7,7,7,7,0
  60.  
  61.  
  62. ;***************************************************************************
  63. ;Interrupt 21H Handler
  64.  
  65. OLD_21H         DD      ?               ;Original INT 21H handler
  66.  
  67. ;This is the interrupt 21H hook. It flags attempts to open COM or EXE files
  68. ;in read/write mode using Function 3DH. It also flags attempts to go memory
  69. ;resident using Function 31H.
  70. INT_21H:
  71.         cmp     ah,31H                  ;something going resident?
  72.         jnz     TRY_3D                  ;nope, check next condition to flag
  73.         cmp     BYTE PTR cs:[FIRST],0   ;first time this is called?
  74.         jz      I21RF                   ;yes, must allow GBC to go resident itself
  75.         call    RESIDENT_FLAG           ;yes, ask user if he wants it
  76.         jz      I21R                    ;he wanted it, go ahead and do it
  77.         mov     ah,4CH                  ;else change to non-TSR terminate
  78.         jmp     SHORT I21R              ;and pass that to DOS
  79. TRY_3D: push    ax
  80.         and     al,2                    ;mask possible r/w flag
  81.         cmp     ax,3D02H                ;is it an open r/w?
  82.         pop     ax
  83.         jnz     I21R                    ;no, pass control to DOS
  84.  
  85.         push    si
  86.         push    ax
  87.         mov     si,dx                   ;ds:si points to ASCIIZ file name
  88. T3D1:   lodsb                           ;get a byte of string
  89.         or      al,al                   ;end of string?
  90.         jz      T3D5                    ;yes, couldnt be COM or EXE, so go to DOS
  91.         cmp     al,'.'                  ;is it a period?
  92.         jnz     T3D1                    ;nope, go get another
  93.         lodsw                           ;get 2 bytes
  94.         or      ax,2020H                ;make it lower case
  95.         cmp     ax,'oc'                 ;are they "co"?
  96.         jz      T3D2                    ;yes, continue
  97.         cmp     ax,'xe'                 ;no, are they "ex"?
  98.         jnz     T3D5                    ;no, not COM or EXE, so go to DOS
  99.         jmp     SHORT T3D3
  100. T3D2:   lodsb                           ;get 3rd byte (COM file)
  101.         or      al,20H                  ;make it lower case
  102.         cmp     al,'m'                  ;is it "m"
  103.         jz      T3D4                    ;yes, it is COM
  104. T3D3:   lodsb                           ;get 3rd byte (EXE file)
  105.         or      al,20H                  ;make lower case
  106.         cmp     al,'e'                  ;is it "e"
  107.         jnz     T3D5                    ;nope, go to original int 21H
  108. T3D4:   pop     ax                      ;if we get here, it's a COM or EXE
  109.         pop     si
  110.  
  111.         call    RDWRITE_FLAG            ;ok, COM or EXE, ask user if he wants it
  112.         jz      I21R                    ;yes, he did, go let DOS do it
  113.         stc                             ;else set carry to indicate failure
  114.         retf    2                       ;and return control to caller
  115.  
  116. T3D5:   pop     ax                      ;not COM or EXE, so clean up stack
  117.         pop     si
  118.         jmp     SHORT I21R              ;and go to old INT 21H handler
  119.  
  120. I21RF:  inc     BYTE PTR cs:[FIRST]     ;update FIRST flag
  121. I21R:   jmp     cs:[OLD_21H]            ;pass control to original handler
  122.  
  123. ;This routine asks the user if he wants a program that is attempting to go
  124. ;memory resident to do it or not. If the user wants it to go resident, this
  125. ;routine returns with Z set.
  126. RESIDENT_FLAG:
  127.         push    ds
  128.         push    si
  129.         push    ax
  130.         call    SAVE_VIDEO              ;save a block of video for our use
  131.         push    cs
  132.         pop     ds
  133.         mov     si,OFFSET RES_FLAG
  134.         call    ASK
  135.         pushf
  136.         call    RESTORE_VIDEO           ;restore saved video
  137.         popf
  138.         pop     ax
  139.         pop     si
  140.         pop     ds
  141.         ret
  142.  
  143. RES_FLAG        DB      7,7,7,'A program is attempting to go resident. Allow it? ',0
  144.  
  145. ;RDWRITE_FLAG asks the user if he wants a COM or EXE file to be opened in read/
  146. ;write mode or not. If he does, it returns with Z set.
  147. RDWRITE_FLAG:
  148.         push    ds
  149.         push    si
  150.         push    ax
  151.         call    SAVE_VIDEO              ;save a block of video for our use
  152.         mov     si,dx
  153.         call    DISP_STRING             ;display file name being opened
  154.         push    cs
  155.         pop     ds
  156.         mov     si,OFFSET RW_FLAG       ;and query user
  157.         call    ASK
  158.         pushf
  159.         call    RESTORE_VIDEO           ;restore saved video
  160.         popf
  161.         pop     ax
  162.         pop     si
  163.         pop     ds
  164.         ret
  165.  
  166. RW_FLAG         DB      7,7,7,' is being opened in read/write mode. Allow it? ',0
  167.  
  168. ;***************************************************************************
  169. ;Resident utility functions
  170.  
  171. ;Ask a question. Display string at ds:si and get a character. If the character
  172. ;is 'y' or 'Y' then return with z set, otherwise return nz.
  173. ASK:
  174.         call    DISP_STRING
  175.         mov     ah,0
  176.         int     16H
  177.         or      al,20H
  178.         cmp     al,'y'
  179.         ret
  180.  
  181. ;This displays a null terminated string on the console.
  182. DISP_STRING:
  183.         lodsb
  184.         or      al,al
  185.         jz      DSR
  186.         mov     ah,0EH
  187.         int     10H
  188.         jmp     DISP_STRING
  189. DSR:    ret
  190.  
  191. ;Save 1st 4 lines of video memory to internal buffer. Fill it with spaces and
  192. ;a line.
  193. SAVE_VIDEO:
  194.         push    ax
  195.         push    bx
  196.         push    cx
  197.         push    dx
  198.         push    si
  199.         push    di
  200.         push    ds
  201.         push    es
  202.         mov     ds,cs:[VIDSEG]          ;ds:si set to video memory
  203.         push    cs
  204.         pop     es                      ;es:di set to internal storage buffer
  205.         xor     si,si
  206.         mov     di,OFFSET VIDEO_BUF
  207.         mov     cx,80*4
  208.         rep     movsw                   ;save 1st 4 lines of video memory
  209.         mov     ah,3                    ;now get cursor position
  210.         mov     bh,0
  211.         int     10H
  212.         mov     cs:[CURSOR],dx          ;and save it here
  213.  
  214.         push    ds
  215.         pop     es
  216.         xor     di,di
  217.         mov     ax,0720H                ;fill 3 lines with spaces
  218.         mov     cx,80*3
  219.         rep     stosw
  220.         mov     ax,0700H+'_'            ;and 1 with a line
  221.         mov     cx,80
  222.         rep     stosw
  223.         mov     ah,2                    ;set cursor position to 0,0
  224.         mov     bh,0
  225.         xor     dx,dx
  226.         int     10H
  227.         pop     es
  228.         pop     ds
  229.         pop     di
  230.         pop     si
  231.         pop     dx
  232.         pop     cx
  233.         pop     bx
  234.         pop     ax
  235.         ret
  236.  
  237. ;Restore 1st 4 lines of video memory from internal buffer.
  238. RESTORE_VIDEO:
  239.         push    ax
  240.         push    bx
  241.         push    cx
  242.         push    dx
  243.         push    si
  244.         push    di
  245.         push    ds
  246.         push    es
  247.         mov     es,cs:[VIDSEG]
  248.         xor     di,di                   ;es:di = video memory
  249.         push    cs
  250.         pop     ds
  251.         mov     si,OFFSET VIDEO_BUF     ;ds:si = internal storage buffer
  252.         mov     cx,80*4
  253.         rep     movsw                   ;restore video memory
  254.         mov     ah,2                    ;restore cursor position
  255.         mov     bh,0
  256.         mov     dx,[CURSOR]
  257.         int     10H
  258.         pop     es
  259.         pop     ds
  260.         pop     di
  261.         pop     si
  262.         pop     dx
  263.         pop     cx
  264.         pop     bx
  265.         pop     ax
  266.         ret
  267.  
  268. ;***************************************************************************
  269. ;Startup code begins here. This part does not stay resident.
  270.  
  271. GO_RESIDENT:
  272.         mov     ah,9                    ;say hello
  273.         mov     dx,OFFSET HELLO
  274.         int     21H
  275.  
  276.         mov     [VIDSEG],0B000H         ;determine video segment to use
  277.         mov     ah,0FH                  ;assume b&w monitor
  278.         int     10H                     ;but ask what mode we're in
  279.         cmp     al,7                    ;is it mode 7
  280.         jz      GR1                     ;yes, it's b&w/hercules
  281.         mov     [VIDSEG],0B800H         ;else assume cga/ega/vga
  282.  
  283. GR1:    mov     ax,3513H                ;hook interrupt 13H
  284.         int     21H                     ;get old vector
  285.         mov     WORD PTR [OLD_13H],bx
  286.         mov     WORD PTR [OLD_13H+2],es
  287.         mov     ax,2513H                ;and set new vector
  288.         mov     dx,OFFSET INT_13H
  289.         int     21H
  290.  
  291.         mov     ax,3521H                ;hook interrupt 21H
  292.         int     21H                     ;get old vector
  293.         mov     WORD PTR [OLD_21H],bx
  294.         mov     WORD PTR [OLD_21H+2],es
  295.         mov     ax,2521H                ;and set new vector
  296.         mov     dx,OFFSET INT_21H
  297.         int     21H
  298.  
  299.         mov     dx,OFFSET GO_RESIDENT   ;now go resident
  300.         mov     cl,4
  301.         shr     dx,cl
  302.         inc     dx
  303.         mov     ax,3100H                ;using Int 21H, Function 31H
  304.         int     21H
  305.  
  306. HELLO   DB      'GB-Behavior Checker v 1.00 (C) 1995 American Eagle Publications, Inc.$'
  307.  
  308.         end     START
  309.